package com.rd.student.dashuju.zhengchengxiang.July13th.Test;


import java.util.LinkedList;
import java.util.Scanner;


class AgeRange {


    public static StringBuilder ageRange(LinkedList list) {

        StringBuilder stringBuilder = new StringBuilder();
        System.out.println("请输入年龄范围，左闭右开(例:18 20):");
        Scanner scanner = new Scanner(System.in);

        int n1 = scanner.nextInt();
        int n2 = scanner.nextInt();
        stringBuilder.append("[");
        for (int i = 0; i < list.size(); i++) {

            Student sr = (Student) list.get(i);


            if (sr.getAge() >= n1 && sr.getAge() < n2) {
//                    if(i == list.size() - 1){
//                        stringBuilder.append("\"").append(sr.getName()).append("\"").append("]");
//                    }else {
//                        stringBuilder.append("\"").append(sr.getName()).append("\"" + ",");
//                    }
                stringBuilder.append("\"").append(sr.getName()).append("\"" + ",");
            }
        }

        // 删除最后一个逗号
        if (stringBuilder.length() > 1 && stringBuilder.charAt(stringBuilder.length() - 1) == ',') {
            stringBuilder.deleteCharAt(stringBuilder.length() - 1);
        }
        stringBuilder.append("]");
        System.out.println(stringBuilder);
        return stringBuilder;
    }
}